index.js ➔ ParameterBag   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
/* ****************************************************************************************************************
2
 * @summary Simple parameter bag module, inspired by Symfony ParameterBag
3
 * @description ParameterBag provide Object oriented way to store key value pair
4
 *
5
 * @example <caption>Instantiation</caption>
6
 * const ParameterBag = require('parameterBag');
7
 * var bag = new ParameterBag();
8
 *
9
 * @example <caption>Setter</caption>
10
 *  bag.set('key', 'value');
11
 *
12
 * @example <caption>Getter</caption
13
 *  var myValue = bag.get('key');
14
 *****************************************************************************************************************/
15
16
/**
17
 * @constructor
18
 */
19
function ParameterBag() {
20 4
    this.store = [];
21
}
22
23
/**
24
 * @public
25
 * @param {string} key
26
 * @param {mixed}  data
27
 */
28 1
ParameterBag.prototype.set = function(key, data) {
29 3
    this.store[key] = data;
30
};
31
/**
32
 * @public
33
 * @param {string} key
34
 * @param {mixed}  defaultValue If value is undefined for the key, defaultValue will be returned
35
 *
36
 * @returns {mixed}
37
 */
38 1
ParameterBag.prototype.get = function(key, defaultValue) {
39 4
    var value = this.store[key];
40 4
    if (typeof value === 'undefined') {
41 2
        return defaultValue;
42
    }
43
44 2
    return value;
45
};
46
47
/**
48
 * @private
49
 * @type {Array}
50
 */
51 1
ParameterBag.prototype.store = null;
52
53
/* Export class */
54
module.exports = ParameterBag;
55